var mongoose = require('mongoose')

var db = mongoose.createConnection('localhost', 'chat')

db.on('error', console.error.bind(console, '数据库连接失败'))

db.once('open', function () {
  console.log('数据库已连接')
})

var userSchema = new mongoose.Schema({
  user: String,
  faceImg: String
})
var infoSchema = new mongoose.Schema({
  user: String,
  content: String,
  faceImg: String,
  time: {
    type: Date,
    default: Date.now()
  }
})

var userModel = db.model('user', userSchema)

var infoModel = db.model('info', infoSchema)

module.exports = {
  User: userModel,
  Info: infoModel
}